package de.dailab.graphworld.bean.utils;

import de.dailab.graphworld.ontology.Node;
import de.dailab.graphworld.ontology.Task;
import java.util.Collection;
import java.util.Iterator;
import java.util.LinkedList;

/**
 *
 * @author Kseniya
 */
public abstract class BeanUtils {

    public static Collection<Task> findTasksByNode(Collection<Task> tasks, Node node) {
        Collection<Task> ret = new LinkedList<>();
        for (Task task : tasks) {
            if (task.goldNode.getID() == node.getID()) {
                ret.add(task);
            }
        }
        return ret;
    }

    public static void removeJobsByNode(Collection<Task> jobs, Task task) {
        Iterator<Task> itr = jobs.iterator();
        while (itr.hasNext()) {
            Task nextJob = itr.next();
            if (nextJob.goldNode.getID() == task.goldNode.getID()) {
                itr.remove();
            }
        }
    }

    public static Task findBestJob(Collection<Task> jobs) {
        if (jobs.isEmpty()) {
            throw new RuntimeException("Can't select a job, no jobs supplied!");
        }
        Iterator<Task> itr = jobs.iterator();
        Task best = itr.next();
        while (itr.hasNext()) {
            Task job = itr.next();
            if (best.goldNode.getGold() < job.goldNode.getGold()) {
                best = job;
            }
        }
        return best;
    }
}
